package cn.edu.hit.education.labelprovider;

import java.util.List;

import org.eclipse.jface.viewers.ITableLabelProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.swt.graphics.Image;
import org.eclipse.ui.ISharedImages;
import org.eclipse.ui.PlatformUI;

import cn.edu.hit.education.pojo.ExCourse;
import cn.edu.hit.education.pojo.Schedule;

public class CourseInformationLabelProvider extends LabelProvider implements
		ITableLabelProvider {
	/*SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss" );*/
	public static String[] OPENS = {"不开","部分","开课"};
	public static String[] SEMESTERS = {"Ⅰ","Ⅱ","Ⅲ","Ⅳ","Ⅴ","Ⅵ","Ⅶ","Ⅷ"};
	
	@Override
	public String getColumnText(Object element, int columnIndex) {
		// TODO Auto-generated method stub
		ExCourse data = (ExCourse) element;
		if(data.getId() == 203){
			System.out.println("203");
		}
		List<Schedule> schedules = data.getSchedules();
		String semesterName = "";
		int isOpen = 0;
		if(schedules != null && schedules.size() > 0){
			for (int i = 0;i < schedules.size();i++) {
				semesterName += SEMESTERS[schedules.get(i).getSemesterId() - 1];
				if(i != schedules.size() - 1){
					semesterName += ",";
				}
				
				isOpen += schedules.get(i).getOpened();
			}
			
			if(isOpen != 0){
				if(isOpen < schedules.size()){
					isOpen = 1;
				}else{
					isOpen = 2;
				}
			}
		}
		
		String unitName = data.getUnit() == null ?  "" : data.getUnit();
		if (columnIndex == 0) {
			return data.getNumber()==null?"":data.getNumber();
		}else if (columnIndex == 1) {
			return data.getName();
		}else if (columnIndex == 2) {
			return String.valueOf(data.getCredits());
		}else if (columnIndex == 3) {
			if(data.getMethod() != null && data.getMethod().trim().equals("分散")){
				return "(" + String.valueOf(data.getPeriod()==null?"":data.getPeriod()) + ") " + unitName;
			}else{
				return String.valueOf(data.getPeriod()==null?"":data.getPeriod()) + " " + unitName;
			}
		}else if (columnIndex == 4) {
			if(data.getMethod() != null && data.getMethod() != null && data.getMethod().trim().equals("分散")){
				return "(" + String.valueOf(data.getTheoretical()==null?"":data.getTheoretical()) + ") " + unitName;
			}else{
				return String.valueOf(data.getTheoretical()==null?"":data.getTheoretical()) + " " + unitName;
			}
		}else if (columnIndex == 5) {
			if(data.getMethod() != null && data.getMethod() != null && data.getMethod().trim().equals("分散")){
				return "(" + String.valueOf(data.getExperiment()==null?"":data.getExperiment()) + ") " + unitName;
			}else{
				return String.valueOf(data.getExperiment()==null?"":data.getExperiment()) + " " + unitName;
			}
		}else if (columnIndex == 6) {
			return semesterName;
		}else if (columnIndex == 7) {
			return OPENS[isOpen];
		}else{
			return "";
		}
	}

	public Image getColumnImage(Object obj, int index) {
		return null;
	}

	public Image getImage(Object obj) {
		return PlatformUI.getWorkbench().getSharedImages()
				.getImage(ISharedImages.IMG_OBJ_ELEMENT);
	}
}